package com.stone.business.gzp.action;

/**
 * <pre>
 * 工作票统计记录
 * @author
 * </pre>
 */

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.stone.business.gzp.pojo.TGzptjjl;
import com.stone.business.gzrwd.service.ZbjlCommonService;
import com.stone.common.action.AdvanceSearchJsonUtils;
import com.stone.para.IConstant;
import com.stone.utils.DateFormatTool;
import com.stone.utils.StringUtils;

import frm.ssh.action.BaseListAction;

public class GzptjjlListAction extends BaseListAction {

	private static final long serialVersionUID = 3979577965804736350L;

	private ZbjlCommonService myService;
	
	public ZbjlCommonService getMyService() {
		return myService;
	}

	public void setMyService(ZbjlCommonService myService) {
		this.service = myService;
		this.myService = myService;
	}
	
    /** * 构造方法. */
    public GzptjjlListAction() {
        this.entityClass = TGzptjjl.class;
    }

	HashMap<String, Object> m = new HashMap<String, Object>();
	/**
	 * 设置查询条件
	 */
	public HashMap<String, Object> setSearchCondition() {
		
		List<Object> valsList = new ArrayList<Object>();
		
		
		m.put("cols", "new map(s.jhgzsjks as jhgzsjks, s.jhgzsjjs as jhgzsjjs,s.xkgzsj as xkgzsj, s.id as id,s.lx as lx,s.bdzname as bdzname, s.ph as ph, s.gzfzrname as gzfzrname, s.gzrw as gzrw,s.qxr as qxr)");
		
//		by wangtao update20110315
		String organCode = String.valueOf(super.getSession().getAttribute(IConstant.SESSION_TORGAN_CODE));
	//		 查询条件OUID很重要
		String conditions = " ";
		 conditions += "  s.fzrdw=5021 and  state = '" + super.getSearchBean().getCon1() + "'"; 
		
		// 巡视时间
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon2())) {
			conditions += " AND TO_CHAR(s.jhgzsjks,'yyyy-MM-dd') >= ?";
			valsList.add(super.getSearchBean().getCon2());
		}
		
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon3())) {
			conditions += " AND TO_CHAR(s.jhgzsjjs,'yyyy-MM-dd') <= ?";
			valsList.add(super.getSearchBean().getCon3());
		}
		
		/*// 变电站
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon4())) {
			conditions += " AND s.bdzname like ?";
			valsList.add("%" + super.getSearchBean().getCon4()+ "%");
		}*/
		// 变电站 by wangtao add20110115
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon4())) {
			conditions += " AND s.bdzname in (";
			StringBuffer buf= new StringBuffer(""); 
			String[] bdznames = ((String) super.getSearchBean().getCon4() == null? "" : super.getSearchBean().getCon4()).split(",");
			
			for (int i=0; i< bdznames.length; i++) { 
			  if (i!=0) buf.append(", "); 
			  buf.append("?"); 
			  valsList.add("" + bdznames[i]+ "");
			  //System.out.println("bdznames["+i+"]=="+bdznames[i]);
			} 
			buf.append(")"); 
			conditions +=buf;

			
		}

		// 查询条件
		m.put("conditions",conditions);
		m.put("clause", " order by s.jhgzsjks Desc");
		//m.put("alias", "s");//, TOrgan o
		m.put("alias", "s");
		m.put("vals", valsList.toArray());
		
	//	DictionaryService dicService = (DictionaryService) SpringUtil.getInstance().getBean("dicService");
	//	xslxList = dicService.findList("XSLX");
		
		return m;
		
	}
	

	/**
	 * 生成csv
	 */
	@Override
	public HashMap<String, Object> createCsvMap() {
		this.setSearchCondition();
		m.put("title", "工作票统计记录");
		m.put("searchcols", "s.jhgzsjks as jhgzsjks, s.jhgzsjjs as jhgzsjjs,s.xkgzsj as xkgzsj, s.id as id,s.lx as lx,dic.itemName as tzlx, s.bdzname as bdzname, s.ph as ph, s.gzfzrname as gzfzrname, s.gzrw as gzrw");
		//m.put("searchcols", "s.jhgzsjks as jhgzsjks, s.jhgzsjjs as jhgzsjjs, s.id as id, s.bdzname as bdzname, s.ph as ph, s.gzfzrname as gzfzrname, s.gzrw as gzrw");
		m.put("colscn", "变电站,计划开始时间, 计划结束时间 ,许可工作时间,票号,类型 ,工作任务");
		m.put("colsen", new String[] {"bdzname","jhgzsjks","jhgzsjjs","xkgzsj","ph","tzlx","gzrw"});
		//m.put("classname", TGzptjjl.class.getName() + " s");
		m.put("classname", TGzptjjl.class.getName() + " s, TDictionary dic");
		
		return m;
	}

}
